<?php
// Allow inclusion for the other files
define('INCLUDE', true);

// Configuration file see doc inside
require_once 'config.php';

// Database file see doc inside (based on SQLite v2)
require_once CORE_DIRECTORY.OS_PATH_SEPARATOR.'database.php';

// Database object is instanced here as well always need it,
// it will be used as a global variable to pass-through multiple instantiations
$DB = new Database(DATABASE);

$plugin = UPLOAD_PLUGINS_DEFAULT;

// Show a specific upload plugin
if(isset($_GET['show']))
{
	$plugin = $_GET['show'];
}

// Template engine initialisation
require_once LIBS_DIRECTORY.OS_PATH_SEPARATOR.'Smarty'.OS_PATH_SEPARATOR.'Smarty.class.php';
$smarty = new Smarty();
$smarty->assign('types', $typesTemplate);

// Load upload plugins
$uploadForm = require_once UPLOAD_PLUGINS_DIRECTORY.OS_PATH_SEPARATOR.'upload.php';

// If an upload plugin handle some files this part allows their processing
if(!empty($files) && !empty($upload))
{
	// Metadata processing
	try
	{
		require_once METADATA_PLUGINS_DIRECTORY.OS_PATH_SEPARATOR.'metadata.php';
	}
	catch(Exception $e)
	{
		debug($e->getMessage(),'Exception', JGLIB_DEBUG_ERRR);
	}
	
	// Thumbnail processing
	try
	{
		require_once THUMBNAIL_PLUGINS_DIRECTORY.OS_PATH_SEPARATOR.'thumbnail.php';
	}
	catch(Exception $e)
	{
		debug($e->getMessage(),'Exception', JGLIB_DEBUG_ERRR);
	}
	
	$upload->success();
}

$smarty->assign('uploadForm', $uploadForm);
$smarty->display('add.tpl');
	
debug('<a href="index.php">Back to the main page</a>');
require_once 'end.php';

